@extends('Layout/adminBase')
@section('css')
<link rel="stylesheet" type="text/css" href="{{asset('/bootstrap/css/bootstrap.min.css')}}">
<style type="text/css">
    .head-div{
        height: 70px;
    }
    .head-div .head-left{
        margin-left:20px;
    }
 
    .main-div{
        padding:50px;
    }
    .main-div .main-form{
        margin-left:230px;
    }
    .middle{
        height: 20px;
        background: #d5d5d8;
    }

</style>
@endsection
@section('body')
	<div class="head-div">
		<div class='head-left'>
		    <h4>添加新上架积分商品</h4>
		</div>
		</div>
		
		<div class="main-div">
		<form class="form-horizontal main-form" role="form" action="javascript:;">
		    <div class="form-group">
		        <label for="firstname" class="col-sm-2 control-label">商品名</label>
		        <div class="col-sm-5">
		            <input type="text" class="form-control" name="name" placeholder="请输入商品名称">
		        </div>
		    </div>
		    <div class="form-group">
		        <label for="firstname" class="col-sm-2 control-label">商品图片</label>
		        <div class="col-sm-5">
		            <input type="file" name="image">
		        </div>
		    </div>
		    <div class="form-group">
		        <label for="firstname" class="col-sm-2 control-label">商品详情</label>
		        <div class="col-sm-5">
		            <textarea class="form-control" rows="3" name="detail" placeholder="请输入商品详情..."></textarea>
		        </div>
		    </div>
		    <div class="form-group">
		        <label for="lastname" class="col-sm-2 control-label">积分价格</label>
		        <div class="col-sm-5">
		            <input type="text" class="form-control"  name='price' placeholder="请输入价格">
		        </div>
		    </div>
		    
		    <div class="form-group">
		        <div class="col-sm-offset-2 col-sm-5">
		            <a  class="btn btn-success btn-add" >添加</a>
		            <button type="reset" class="btn btn-default">重置</button>
		        </div>
		    </div>
		</form>
	</div>
@endsection

@section('footer-js')
	<script type="text/javascript">

		
		$('.btn-add').click(function () { 
			var name = $('input[name="name"]').val();
			var image = $('input[name="image"]').val();
			var detail = $('textarea[name="detail"]').val();
			var price = $('input[name="price"]').val();
			//var status = $('select[name="status"]').val();
			var token  = "{{csrf_token()}}";
			$.ajax({ 
				url: "{{url('admin/integral/store')}}",
				type: 'post',
				data: {'name':name, 'image':image, 'detail':detail, 'price':price, '_token':token},
				datatype: 'json',
				success:function (data) {

					//console.log(data);

					if (data.code == 2000) {
	                    var div =  "<div class='alert alert-success alert-mess'>"+data.msg+"</div>";
	                    $('.alert-mess').remove();
	                    $('.main-div').prepend(div);
	                    setTimeout(function () {                 
	                        location.href = "{{url('admin/integral/create')}}";
	                    }, 1000)
	                } else {
	                    var div =  "<div class='alert alert-danger alert-mess'>"+data.msg+"</div>";
	                    $('.alert-mess').remove();
	                    $('.main-div').prepend(div);
	                }
				},
				error: function (tipString) {
		          	//console.log(tipString.responseText);
		           	var text = JSON.parse(tipString.responseText).errors;
	                var div = "<div class='alert alert-danger alert-mess'><ul>";
	                if (text) {
	                    for (var key in text) {
	                        div += "<li>"+text[key][0]+"</li>";
	                    }
	                } else {
	                    div += "<li>"+"未知错误"+"</li>";
	                }
	                div += '</ul></div>';
	                $('.alert-mess').remove();
	                $('.main-div').prepend(div);
		        },
			});
			
		})
	</script>
@endsection